﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Encodings.Web;
using Kugar.Core.ExtMethod;
using Kugar.Core.Web;
using Kugar.UI.Web.AdminLTE.Helpers;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Kugar.UI.Web.AdminLTE.PageControls.PageForms
{
    public  class PageForm_CustomContentField:PageForm_SingleInputFieldBase
    {
        private string _content = null;
        private bool _hasError = false;
        private string _errorMsg = "";
        private string _errorValidateName = "";
        private ControlBase _ctrl = null;

        public PageForm_CustomContentField(PageForm_Form form, ViewContext viewContext) : base(form, viewContext)
        {
            this.Css("webui-form_customcontentfield");
        }

        public PageForm_CustomContentField Content(Func<object, HelperResult> content)
        {
            _content = content(this).ToHtmlString();
            _ctrl = null;
            return this;
        }

        public PageForm_CustomContentField Content(ControlBase ctrl)
        {
            _ctrl = ctrl;
            _content = "";

            return this;
        }

        protected override void RenderContent(TextWriter writer)
        {
            //_content.WriteTo(writer,HtmlEncoder.Default);

            if (_ctrl!=null)
            {
                _ctrl.Render();
            }
            else
            {
                writer.WriteLine(_content);
            }
            

            
        }
    }
}
